<?php
/**
 * @authors alex (20779512@qq.com)
 * @date    2014-03-24 16:49:33
 * @version 1.0
 */

class UploadAction extends BaseAction {    

    public function index(){
        if($_FILES){
            $path = '.'.C('UPLOAD_PATH').'card/';    
            import("ORG.Net.UploadFile");
            $upload=new UploadFile();
            $upload->maxSize = C('image_size')*1000;  //是指上传文件的大小，默认为-1,不限制上传文件大小bytes
            $upload->savePath = $path;        //上传保存到什么地方？路径建议大家已主文件平级目录或者平级目录的子目录来保存
            $upload->autoSub = true;
            $upload->subType = 'date';
            $upload->dateFormat = 'Ym';
            $upload->saveRule=uniqid;    //上传文件的文件名保存规则  time uniqid  com_create_guid  uniqid
            $upload->uploadReplace=true;     //如果存在同名文件是否进行覆盖
            $upload->allowExts= explode(',',C('image_exts'));     //准许上传的文件后缀
            $upload->thumb = true;
            $upload->thumbMaxWidth = '600';
            $upload->thumbMaxHeight=  '400';
            $upload->thumbPrefix = 'card_';// 缩略图前缀
            $upload->thumbRemoveOrigin =true;// 是否移除原图
            $upload->thumbType = 0; 
            if($upload->upload()){
                $info=$upload->getUploadFileInfo();
                $url = C('UPLOAD_PATH').'card/'.dirname($info[0]["savename"]).'/'.'card_'.basename($info[0]["savename"]);
                echo $this->echo_json_str('SUCCESS' , '' , $url); 
            }else{
                //是专门来获取上传的错误信息的 
                echo $this->echo_json_str($upload->getErrorMsg(),''); 
            }
        }else{
            echo $this->echo_json_str('请选择照片' , '');
        }
    } 
}